#ifndef ROSYAMA_H
#define ROSYAMA_H

#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QUrl>
#include <QPointF>

#include "formpost.h"

class RosYama : public QObject
{
    Q_OBJECT
public:
    explicit RosYama(QObject *parent = 0);

    bool checkAuth();
    void exit();

    void getLimits();

    Q_INVOKABLE void setServer(QString xmlBase, QString htmlBase);
    Q_INVOKABLE void authorize(QString login, QString password);
    Q_INVOKABLE void geocode(QPointF coord);
    Q_INVOKABLE void submitHole(QString address, QPointF coord, QString comment, QString type, QVariantList photos);
    Q_INVOKABLE void listHoles();

    // Ugly, ugly hack, but still better than polluting user's gallery with crap.
    // Probably needs to be redone through DocumentGallery inside QML.
    Q_INVOKABLE void removeFile(QString path);

signals:
    void errorMessage(QString error);

    void loginResult(bool loginOk);
    void geocodeResult(QString result);
    void submitHoleResult(bool submitOk);
    void listHolesResult(QString address, QString status, QString type, QString date, QString image);

public slots:
    void loginCallback();
    void geocodeCallback();
    void submitHoleCallback();
    void listHolesCallback();

private:
    QNetworkAccessManager manager;
    QString login, password, passwordHash;
    QString fullname, name, secondname, lastname;
    QString xmlBase, htmlBase;
    int userId;

    QNetworkReply *loginReply;
    QNetworkReply *geocodeReply;
    QNetworkReply *submitHoleReply;
    QNetworkReply *listHolesReply;

    FormPost *formPost;
};

#endif // ROSYAMA_H
